#include "RingQueue.hpp"
#include <unistd.h>
#include <iostream>
using namespace std;

// 生产者
void *produce(void *args)
{
    RingQueue<int> *q = static_cast<RingQueue<int> *>(args);
    for (int i = 0;; i++)
    {
        q->Equeue(i);
        cout << "生产一个数据：" << i << endl;
    }
}

// 消费者
void *consume(void *args)
{
    RingQueue<int> *q = static_cast<RingQueue<int> *>(args);
    while (1)
    {
        sleep(1);
        int num = q->Pop();
        cout << "消费一个数据：" << num << endl;
    }
}

int main()
{
    RingQueue<int> bq;
    pthread_t t1, t2;
    pthread_create(&t1, nullptr, produce, &bq);
    pthread_create(&t2, nullptr, consume, &bq);

    pthread_join(t1, nullptr);
    pthread_join(t2, nullptr);
}